package com.smh.controller;

import com.smh.pojo.ClassInfo;
import com.smh.service.serviceImpl.ClassServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Controller
@RequestMapping("/class")
public class ClassController {

    @Autowired
    private ClassServiceImpl classService;


    @RequestMapping
    public String init(){
        return "/class/index";
    }

    @ResponseBody
    @PostMapping("add")
    public String add(ClassInfo classInfo){
        log.info("{}",classInfo.getClassName());
        return classService.add(classInfo);
    }

    @ResponseBody
    @GetMapping("search")
    public List<ClassInfo> search(){
        log.info("zhixingle");
        return classService.search();
    }

    @ResponseBody
    @PostMapping("delete")
    public String delete(ClassInfo classInfo){
        classService.delete(classInfo);
        return "ok";
    }

    @ResponseBody
    @PostMapping("update")
    public String update(ClassInfo classInfo){
        classService.update(classInfo);
        return "ok";
    }

    @ResponseBody
    @PostMapping("query")
    public ClassInfo queryById(ClassInfo classInfo){
        return classService.query(classInfo);
    }


}
